//
//  SYDTravelDetailController.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/15.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDTravelDetailController.h"
#import "SYDTravelTrackBottonView.h"
#import "SYDStationModel.h"
#import "SYDEndTheTripView.h"
#import "NaviPointAnnotation.h"
#import "SYDCusAnnotationView.h"
#import "SYDCalloutView.h"
#import "YMUserPointAnnotation.h"
@interface SYDTravelDetailController ()<MAMapViewDelegate,UIGestureRecognizerDelegate,TravelTrackBottonViewDelegate>
{
    CLLocationCoordinate2D coords1[1];
}
//高德地图
@property (nonatomic, strong) MAMapView *mapView;

///支持动画效果的点标注
@property (nonatomic, strong) YMUserPointAnnotation* annotation;

//地图view
@property(nonatomic,strong)SYDTravelTrackBottonView *trackBottonView;

@property (nonatomic, strong) MAUserLocation *currentUL;//当前位置

@property(nonatomic,copy)NSString *firstStationName;
@property(nonatomic,copy)NSString *lastStationName;
@property(nonatomic,copy)NSString *totalCount;
@property(nonatomic,copy)NSString *totalDistance;
@property(nonatomic,copy)NSString *totalIncome;
@property(nonatomic,copy)NSString *totalTimeConsuming;

@property (nonatomic, strong) SYDCalloutView *calloutMapAnnotation;
@property(nonatomic,assign)BOOL showMakerInfo;
//站点
@property (nonatomic, assign) CGFloat mapCenterLon;//地图中心点经度
@property (nonatomic, assign) CGFloat mapCenterLat;//地图中心点纬度
@property (nonatomic, strong) NSMutableArray *mapStationList;//地图站点数组
@property(nonatomic,strong)NSMutableArray *stations;//站点数组
//画线
@property (nonatomic, strong) MAPolyline *routeLine;
@property (nonatomic, strong) NSMutableArray *pointArr;//定位信息数组
@end

@implementation SYDTravelDetailController

#pragma mark - 导航栏
- (void)navigationBarHandle{
    // 导航栏返回按钮
    WEAKSELF
    [self backButtonAction:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
}

#pragma mark---Lazy
- (MAMapView *)mapView{
    if (!_mapView) {
        //地图初始化
        if (iPhone8_X) {
            _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0, 88, SCREEN_WIDTH, SCREEN_HEIGHT - 88)];
        } else {
            _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
        }
        _mapView.compassOrigin = CGPointMake(_mapView.compassOrigin.x, kDefaultControlMargin);
        _mapView.scaleOrigin = CGPointMake(_mapView.scaleOrigin.x, kDefaultControlMargin);
        //改变地图Logo”、“指南针”和“比例尺”三种地图控件
        _mapView.logoCenter = CGPointMake(1000, 450);
        _mapView.logoCenter = CGPointMake(CGRectGetWidth(self.view.bounds)-55, 450);
        //self.mapView.showsLabels = NO;
        _mapView.showsCompass = NO;//不显示指南针
        _mapView.showsScale = NO;//不显示比例尺
        
        _mapView.delegate = self;
        _mapView.showsUserLocation = NO;
        _mapView.rotateEnabled = NO;
        _mapView.showsIndoorMap = YES;
        _mapView.rotateCameraEnabled= NO;    //NO表示禁用倾斜手势，YES表示开启
        _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;
        _mapView.zoomLevel = 13;
    }
    return _mapView;
}
- (NSMutableArray *)mapStationList{
    if (!_mapStationList) {
        _mapStationList = [NSMutableArray array];
    }
    return _mapStationList;
}
-(NSMutableArray *)stations{
    if (!_stations) {
        _stations = [NSMutableArray array];
    }
    return _stations;
}
-(SYDTravelTrackBottonView *)trackBottonView{
    if (!_trackBottonView) {
        _trackBottonView = [[SYDTravelTrackBottonView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 85, SCREEN_WIDTH, 85)];
        _trackBottonView.delegate  = self;
        _trackBottonView.backgroundColor = WHITE_COLOR;
        [self.view addSubview:_trackBottonView];
    }
    return _trackBottonView;
}
#pragma mark - 高德地图初始化
- (void)initMapView{
    //1.判断key是否存在
    if ([MAMAP_KEY length] == 0) {
        NSString *reson = [NSString stringWithFormat:@"apikey为空,请检查key设置时候正确"];
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:reson preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancel];
        [alert presentViewController:self animated:NO completion:nil];
    }
    [YMMaMapServices start];
    
    if (self.mapView.userTrackingMode != MAUserTrackingModeFollow) {
        self.mapView.userTrackingMode = MAUserTrackingModeNone;
        [self.mapView setZoomLevel:13 animated:YES];
    }
    [self.view addSubview:self.mapView];
}
-(NSMutableArray *)pointArr{
    if (!_pointArr) {
        _pointArr = [NSMutableArray array];
    }
    return _pointArr;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //初始化地图
    [self initMapView];
    //获取行程详情
    [self getMyTrailDetailMessage];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationBar.title = @"行程轨迹";
    [self navigationBarHandle];
    
    [self addUpAndDownGes];//上下手势
}
#pragma mark---获取行程轨迹
-(void)getMyTrailDetailMessage{
    
    NSDictionary *dict = [NSString resourcePathWithFileName:@"CarpoolDynamics.json"];
    TravelDetailModel *model = [TravelDetailModel mj_objectWithKeyValues:dict[@"obj"]];
    self.firstStationName = model.firstStationName;
    self.lastStationName = model.lastStationName;
    self.totalDistance = model.totalDistance;
    self.totalTimeConsuming = model.totalTimeConsuming;
    self.totalIncome = model.totalIncome;
    self.totalCount = model.totalCount;
    //添加标注
    [self addStationAnnotationsAndPolylinesWith:model];
//     WEAKSELF
//    [[SYDNetwork shareTool]getMyTrailDetailWithOrderNo:self.regularRouteOrderNo success:^(NSURLSessionDataTask *task, id responseObject) {
//       @try {
//           if ([responseObject[@"statusCode"]integerValue] == 200) {
//               if ([responseObject[@"obj"]isKindOfClass:[NSDictionary class]]) {
//                   TravelDetailModel *model = [TravelDetailModel mj_objectWithKeyValues:responseObject[@"obj"]];
//                   
//                   self.firstStationName = model.firstStationName;
//                   self.lastStationName = model.lastStationName;
//                   self.totalDistance = model.totalDistance;
//                   self.totalTimeConsuming = model.totalTimeConsuming;
//                   self.totalIncome = model.totalIncome;
//                   self.totalCount = model.totalCount;
//                   //添加标注
//                   [weakSelf addStationAnnotationsAndPolylinesWith:model];
//                   [weakSelf addBottonView];
//               }
//           }else{
//               [SVProgressHUD displayInfoWithStatus:responseObject[@"msg"]];
//           }
//       } @catch (NSException *exception) {
//           NSLog(@"%@",exception.description);
//       } @finally {
//           
//       }
//   } failure:^(NSURLSessionDataTask *task, NSError *error) {
//       NSLog(@"%@",error);
//   }];
}
#pragma mark---轨迹和站点标注数据
-(void)addStationAnnotationsAndPolylinesWith:(TravelDetailModel *)model{
    NSArray *Polylines = [model.trailDetail componentsSeparatedByString:@","];
    WEAKSELF
    [Polylines enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSArray *coord = [obj componentsSeparatedByString:@"|"];
        coordModel *coordM = [[coordModel alloc]init];
        coordM.latitude = coord[1];
        coordM.longitude = coord[0];
        [weakSelf.pointArr addObject:coordM];
    }];
    CGFloat locationLat;
    CGFloat locationLong;
    if (weakSelf.pointArr.count % 2 == 0) {
        coordModel *coordM = weakSelf.pointArr[weakSelf.pointArr.count / 2];
        locationLat = [coordM.latitude floatValue];
        locationLong = [coordM.longitude floatValue];
    }else{
        //NSLog(@"--%@",weakSelf.pointArr[(weakSelf.pointArr.count -1) / 2]);
        coordModel *coordM = weakSelf.pointArr[(weakSelf.pointArr.count -1) / 2];
        locationLat = [coordM.latitude floatValue];
        locationLong = [coordM.longitude floatValue];
    }
    
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(locationLat,locationLong);
    [self.mapView setCenterCoordinate:centerCoordinate];

    
        coordModel *coordFirst = weakSelf.pointArr[0];
        coordModel *coordLast = weakSelf.pointArr.lastObject;
        NaviPointAnnotation *startAnnotation = [[NaviPointAnnotation alloc]init];
        startAnnotation.navPointType = NaviPointAnnotationStart;
        startAnnotation.coordinate = CLLocationCoordinate2DMake([coordFirst.latitude floatValue], [coordFirst.longitude floatValue]);;
        startAnnotation.title = model.firstStationName;
        [self.mapView addAnnotation:startAnnotation];
    
    
        NaviPointAnnotation *endAnnotation = [[NaviPointAnnotation alloc]init];
        endAnnotation.navPointType = NaviPointAnnotationEnd;
        endAnnotation.coordinate = CLLocationCoordinate2DMake([coordLast.latitude floatValue], [coordLast.longitude floatValue]);
        endAnnotation.title = model.lastStationName;
        [self.mapView addAnnotation:endAnnotation];
    
    if (self.mapStationList.count > 0) {
        [self.mapStationList removeAllObjects];
    }
    //添加站点
    self.mapStationList = [carpoolRouteStationModel mj_objectArrayWithKeyValuesArray:model.carpoolRouteStations];
    [self addPointAnnotations:self.mapStationList];
    
    //add overlay=------画轨迹
    [self initCoordinates];
}
/**添加地图标注--站点*/
- (void)addPointAnnotations:(NSArray *)points{
    
    if (self.stations.count > 0) {
        [self.stations removeAllObjects];
        [self.mapView removeAnnotations:self.stations];
    }
    
    NSMutableArray * coors = [NSMutableArray array];
    [points enumerateObjectsUsingBlock:^(carpoolRouteStationModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        YMUserPointAnnotation *pointAnnotation = [[YMUserPointAnnotation alloc]init];
        pointAnnotation.coordinate = CLLocationCoordinate2DMake([obj.stationLat floatValue], [obj.stationLon floatValue]);
        pointAnnotation.timeStr = obj.arriveTime;
        pointAnnotation.locationStr = obj.stationName;
        if (![obj.upNum isEqualToString:@""]&&![obj.downNum isEqualToString:@""]) {
            pointAnnotation.numberStr = [NSString stringWithFormat:@"上车%@人,下车%@人",obj.upNum,obj.downNum];
        }else if ([obj.upNum isEqualToString:@""]&&![obj.downNum isEqualToString:@""]){
           pointAnnotation.numberStr = [NSString stringWithFormat:@"下车%@人",obj.downNum];
        }else if (![obj.upNum isEqualToString:@""]&&[obj.downNum isEqualToString:@""]){
          pointAnnotation.numberStr = [NSString stringWithFormat:@"上车%@人",obj.upNum];
        }
        pointAnnotation.index = idx;
        pointAnnotation.pointType = DetailMapPointAnnotationStation;
        [coors addObject:pointAnnotation];
    }];
    
    [self.stations addObjectsFromArray:coors];
    [self.mapView addAnnotations:self.stations];
}
/**绘制路径*/
- (void)initCoordinates {
    
    CLLocationCoordinate2D coords[self.pointArr.count];
    
    for (int i = 0; i < self.pointArr.count; i++) {
        coordModel *coordM= self.pointArr[i];
        if (i==0) {
            coords1[0].latitude = [coordM.latitude doubleValue];
            coords1[0].longitude = [coordM.longitude doubleValue];
        }
        coords[i].latitude = [coordM.latitude doubleValue];
        coords[i].longitude = [coordM.longitude doubleValue];
        
    }
    MAPolyline *polyline1 = [MAPolyline polylineWithCoordinates:coords count:sizeof(coords) / sizeof(coords[0])];
    [self.mapView addOverlays:@[polyline1]];
    
}
#pragma mark - 下滑手势响应
-(void)addUpAndDownGes{
    UISwipeGestureRecognizer * recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [self.view addGestureRecognizer:recognizer];
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.view addGestureRecognizer:recognizer];
}


#pragma mark - MAMapViewDelegate
// 刷新用户位置信息
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
    
}

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
    if ([overlay isKindOfClass:[MAPolyline class]])
    {
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:(MAPolyline *)overlay];
        polylineRenderer.lineWidth    = 8.f;
        [polylineRenderer loadStrokeTextureImage:[UIImage imageNamed:@"arrowTexture"]];
        return polylineRenderer;
        
    }
    
    return nil;
}
/**
 * 根据anntation生成对应的View
 * @param mapView 地图View
 * @param annotation 指定的标注
 * @return 生成的标注View
 */
-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[NaviPointAnnotation class]])
    {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
        annotationView.animatesDrop = NO;
        annotationView.canShowCallout= YES; //设置气泡可以弹出，默认为NO
        annotationView.draggable = NO;
        
        NaviPointAnnotation *navAnnotation = (NaviPointAnnotation *)annotation;
        if (navAnnotation.navPointType == NaviPointAnnotationStart) {
            [annotationView setPinColor:MAPinAnnotationColorGreen];
            
            annotationView.image = [UIImage imageNamed:@"icon_map_start"];
            annotationView.frame = CGRectMake(0, 0, 24, 24);
        }else if (navAnnotation.navPointType == NaviPointAnnotationEnd){
            
            [annotationView setPinColor:MAPinAnnotationColorRed];
            annotationView.image = [UIImage imageNamed:@"icon_map_end"];
            annotationView.frame = CGRectMake(0, 0, 24, 24);
        }
        
        return annotationView;
    }else if ([annotation isKindOfClass:[YMUserPointAnnotation class]]){
        
        static NSString *userLocationStyleIndetifier = @"userLocationStyleIndetifier";
        YMUserPointAnnotation * pointAnnotation = (YMUserPointAnnotation *)annotation;
        SYDCusAnnotationView * annotationView = (SYDCusAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:userLocationStyleIndetifier];
        if (annotationView == nil) {
            annotationView = [[SYDCusAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:userLocationStyleIndetifier];
        }
        if (pointAnnotation.pointType == DetailMapPointAnnotationStation) {
            
            annotationView.markerImage = @"icon_map_pathway_site";
            annotationView.showBottomTitle = _showMakerInfo;
            annotationView.enabled = NO;
            annotationView.markerSize = CGSizeMake(18, 18);
            //NSLog(@"----%@-%@-%@",pointAnnotation.timeStr,pointAnnotation.numberStr,pointAnnotation.locationStr);
            annotationView.pointAnnotation = pointAnnotation;
        }
        return annotationView;
    }else if ([annotation isKindOfClass:[LTYPointAnnotation class]])
    {
        //站点
        LTYPointAnnotation * pointAnnotation = (LTYPointAnnotation *)annotation;
        static NSString *pointReuseIndentifier = @"stationPointReuseIndentifier";
        SYDCusAnnotationView * annotationView = (SYDCusAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil)
        {
            annotationView = [[SYDCusAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
            annotationView.calloutOffset = CGPointMake(0, -1);
        }
        
        annotationView.markerImage = @"icon_map_pathway_site";
        annotationView.locationStr = pointAnnotation.title;
        //annotationView.showBottomTitle = self.showMakerInfo;
        annotationView.enabled = NO;
        
        return annotationView;
    }else if ([annotation isKindOfClass:[MAPointAnnotation class]]){
        
    }
    return nil;
}
/**
 *  地图将要发生缩放时调用此接口
 *
 *  @param mapView       地图view
 *  @param wasUserAction 标识是否是用户动作
 */
- (void)mapView:(MAMapView *)mapView mapWillZoomByUser:(BOOL)wasUserAction{
    if (mapView.zoomLevel <14) {
        _showMakerInfo = NO;
        
    }else{
        
        _showMakerInfo = YES;
    }
    
    [self goAwayAddPointAnnotations:self.mapStationList];
}
#pragma mark---重新添加标注
- (void)goAwayAddPointAnnotations:(NSArray *)points{
    
    [self.mapView removeAnnotations:self.stations];
    
    NSMutableArray * coors = [NSMutableArray array];
    [points enumerateObjectsUsingBlock:^(carpoolRouteStationModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        YMUserPointAnnotation *pointAnnotation = [[YMUserPointAnnotation alloc]init];
        
        pointAnnotation.coordinate = CLLocationCoordinate2DMake([obj.stationLat floatValue], [obj.stationLon floatValue]);
        pointAnnotation.timeStr = obj.arriveTime;
        if (![obj.upNum isEqualToString:@""]&&![obj.downNum isEqualToString:@""]) {
            pointAnnotation.numberStr = [NSString stringWithFormat:@"上车%@人,下车%@人",obj.upNum,obj.downNum];
        }else if ([obj.upNum isEqualToString:@""]&&![obj.downNum isEqualToString:@""]){
            pointAnnotation.numberStr = [NSString stringWithFormat:@"下车%@人",obj.downNum];
        }else if (![obj.upNum isEqualToString:@""]&&[obj.downNum isEqualToString:@""]){
            pointAnnotation.numberStr = [NSString stringWithFormat:@"上车%@人",obj.upNum];
        }
        pointAnnotation.locationStr = obj.stationName;
        pointAnnotation.index = idx;
        pointAnnotation.pointType = DetailMapPointAnnotationStation;
        [coors addObject:pointAnnotation];
    }];
    
    if (coors.count > 0) {
        [self.stations removeAllObjects];
        [self.stations addObjectsFromArray:coors];
    }
    [self.mapView addAnnotations:self.stations];
}
//定位失败
- (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error {
    NSString *errorString = @"";
    switch([error code]) {
        case kCLErrorDenied:
            //Access denied by user
            errorString = @"Access to Location Services denied by user";
            break;
        case kCLErrorLocationUnknown:
            //Probably temporary...
            errorString = @"Location data unavailable";
            //Do something else...
            break;
        default:
            errorString = @"An unknown error has occurred";
            break;
    }
}
#pragma mark---移除地图,销毁控制器
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self clearMapView];
}
#pragma mark - clear mapview
- (void)clearMapView {
    self.mapView.showsUserLocation = NO;
    
    [self.mapView removeAnnotations:self.mapView.annotations];
    
    [self.mapView removeOverlays:self.mapView.overlays];
    self.mapView.delegate = nil;
    [self.mapView removeFromSuperview];
    self.mapView = nil;
}
-(void)dealloc{
    printf(__PRETTY_FUNCTION__);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
//NSDictionary *orderData = [NSString resourcePathWithFileName:@"CarpoolDynamics.json"];
//self.dataArr = orderData[@"obj"][@"assistStations"];
//MAAnimatedAnnotation *anno = [[MAAnimatedAnnotation alloc] init];
//anno.title = @"znb";
//anno.coordinate = coords1[0];
//self.annotation = anno;
//[self.mapView setSelectedAnnotations:@[anno]];
//[self.mapView addAnnotation:self.annotation];
////add overlay
//[self initCoordinates];
//[self initButton];
//- (void)initCoordinates {
//
//    CLLocationCoordinate2D coords[self.dataArr.count];
//    
//    for (int i = 0; i < self.dataArr.count; i++) {
//        NSDictionary *dict= self.dataArr[i];
//        if (i==0) {
//            coords1[0].latitude = [dict[@"latitude"] doubleValue];
//            coords1[0].longitude = [dict[@"longitude"] doubleValue];
//        }
//        coords[i].latitude = [dict[@"latitude"] doubleValue];
//        coords[i].longitude = [dict[@"longitude"] doubleValue];
//        
//    }
//    MAPolyline *polyline1 = [MAPolyline polylineWithCoordinates:coords count:sizeof(coords) / sizeof(coords[0])];
//    [self.mapView addOverlays:@[polyline1]];
//    
//}
//
//- (void)initButton
//{
//    UIButton *button1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//    button1.frame = CGRectMake(10, 100, 70,25);
//    button1.backgroundColor = [UIColor redColor];
//    [button1 setTitle:@"Go" forState:UIControlStateNormal];
//    [button1 addTarget:self action:@selector(button1) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button1];
//    
//    UIButton *button2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//    button2.frame = CGRectMake(10, 150,70,25);
//    button2.backgroundColor = [UIColor redColor];
//    [button2 setTitle:@"Stop" forState:UIControlStateNormal];
//    [button2 addTarget:self action:@selector(button2) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button2];
//}
//
//- (void)button1 {
//    
//    self.annotation.coordinate = coords1[0];
//    MAAnimatedAnnotation *anno = self.annotation;
//    CLLocationCoordinate2D coords[1];
//    __weak __typeof(anno) WeakAnno = anno;
//    NSDictionary *dict= self.dataArr[0];
//    anno.title = dict[@"speed"];
//    for (int i = 1; i < self.dataArr.count; i++) {
//        NSDictionary *dict= self.dataArr[i];
//        coords[0].latitude = [dict[@"latitude"] doubleValue];
//        coords[0].longitude = [dict[@"longitude"] doubleValue];
//        [anno addMoveAnimationWithKeyCoordinates:coords count:sizeof(coords) / sizeof(coords[0]) withDuration:.5 withName:nil completeCallback:^(BOOL isFinished) {
//            WeakAnno.title = dict[@"speed"];
//        }];
//    }
//    
//}
//
//- (void)button2 {
//    for(MAAnnotationMoveAnimation *animation in [self.annotation allMoveAnimations]) {
//        [animation cancel];
//    }
//    
//    self.annotation.movingDirection = 0;
//    self.annotation.coordinate = coords1[0];
//}
//#pragma mark - MAMapViewDelegate
//- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
//{
//    if ([overlay isKindOfClass:[MAPolyline class]])
//    {
//        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:(MAPolyline *)overlay];
//        polylineRenderer.lineWidth    = 8.f;
//        [polylineRenderer loadStrokeTextureImage:[UIImage imageNamed:@"arrowTexture"]];
//        return polylineRenderer;
//    }
//    
//    return nil;
//}
//
//- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
//{
//    if ([annotation isKindOfClass:[MAPointAnnotation class]])
//    {
//        NSString *pointReuseIndetifier = @"myReuseIndetifier";
//        MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
//        if (annotationView == nil)
//        {
//            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation
//                                                             reuseIdentifier:pointReuseIndetifier];
//            
//            UIImage *imge  =  [UIImage imageNamed:@"userPosition"];
//            annotationView.image =  imge;
//        }
//        
//        annotationView.canShowCallout               = YES;
//        annotationView.animatesDrop                 = NO;
//        annotationView.draggable                    = NO;
//        [annotationView setSelected:YES animated:NO];
//        return annotationView;
//    }
//    
//    return nil;
//}


